'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  app.beforeStart(async () => {
    await app.model.sync({
      alter: true
    }); //force  false 为不覆盖 true会删除再创建; alter true可以 添加或删除字段;
  });
  const {
    router,
    controller
  } = app;
  router.get('/', controller.home.index);
  // cook
  router.get('/cook/getAll', controller.cookBook.show);
  router.get('/cook/search', controller.cookBook.search);
  router.post('/cook/add', controller.cookBook.create);
  router.post('/cook/setState', controller.cookBook.changeState);
  router.post('/cook/setType', controller.cookBook.changeType);
  router.get('/cook/findById', controller.cookBook.findById);
  router.get('/cook/findByCategoryId', controller.cookBook.findByCategoryId);
  router.get('/cook/findMaterailById', controller.cookBook.findMaterailById);
  router.get('/cook/findStepById', controller.cookBook.findStepById);
  router.post('/cook/setFavoriteCount', controller.cookBook.setFavoriteCount);
  router.get('/cook/count', controller.cookBook.count);
  router.get('/cook/newShow', controller.cookBook.newShow);
  router.post('/cook/addStep', controller.cookBook.addStep);
  router.post('/cook/addMaterial', controller.cookBook.addMaterial);

  // user
  router.get('/user/getUser', controller.users.getUser)
  router.post('/user/register', controller.users.register)
  router.post('/user/login', controller.users.login)
  // category
  router.get('/category/getAll', controller.category.show)
  router.post('/category/add', controller.category.create)
  router.post('/category/update', controller.category.update)
  router.get('/category/del', controller.category.destroy)

  // favorite
  router.get('/favorite/getAll', controller.favorite.show)
  router.post('/favorite/cancel', controller.favorite.cancel)
  router.post('/favorite/setFavoriteCount', controller.favorite.setFavoriteCount);
};